package com.bwie.controller;

import com.bwie.common.domain.User;
import com.bwie.common.result.Result;
import com.bwie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @className: UserController
 * @Description: TODO
 * @version: v1.８.0
 * @author: 李明
 * @date: 2025/10/22 9:50
 */
@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 根据用户名称和密码查询该用户是否存在
     */
    @GetMapping("getUserInfo/{username}")
    public Result<User> getUserInfo(@PathVariable("username") String username){
        User user = userService.getUserInfo(username);
        return Result.success(user);
    }

    /**
     * 根据手机号查询用户信息
     */
    @GetMapping("getUserByPhone/{phone}")
    public Result<User> getUserByPhone(@PathVariable("phone") String phone){
        User user = userService.getUserByPhone(phone);
        return Result.success(user);
    }

    /**
     * 注册用户
     */
    @PostMapping("addUserInfo")
    public Result addUserInfo(@RequestBody User user){
        userService.addUserInfo(user);
        return Result.success();
    }

}
